﻿package game.context {
	
	import flash.ui.ContextMenu;
	import flash.ui.ContextMenuItem;
	import flash.events.ContextMenuEvent;
	import flash.net.URLRequest;
	
	public dynamic class Context {
		
		public static function get(objects:Array):ContextMenu {
			
			var menu:ContextMenu = new ContextMenu;
			menu.hideBuiltInItems();
			menu.builtInItems.quality = true;
			
			var item:ContextMenuItem;
			for each (var object:ContextObject in objects) {
				menu.customItems.push( addContextMenu (object.label, object.onFunction) );
			}
			
			return menu;
		}
		
		public static function addContextMenu(label:String, func:* = null, enabled:Boolean = true, separatorBefore:Boolean = false):ContextMenuItem { 
			var cmi:ContextMenuItem = new ContextMenuItem (label);
			cmi.separatorBefore = separatorBefore;
			cmi.enabled = enabled;
			cmi.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, function(evt:ContextMenuEvent) { func() });
			
			return cmi;
		}
		
	}
	
}